import type { ApiPagination, ApiPaginationParams } from '#types/utils'
import { requestClient } from '../request'
import type { sellerItemForm, sellerPageListItem } from './model/work'
import { useAppConfig } from '@vben/hooks'
const { apiURL } = useAppConfig(import.meta.env, import.meta.env.PROD)

// 注册
export default class CustomerSellerApi {
    static get inst() {
        return CustomerSellerApi._inst || (CustomerSellerApi._inst = new CustomerSellerApi())
    }
    private static _inst: CustomerSellerApi
    /**
     * 注册分页 
     * @param params
     */
    getPageList(params: ApiPaginationParams<{ username?: string }>) {
        return requestClient.get<ApiPagination<sellerPageListItem>>(
            '/stockRegisterLog/index',
            {
                params
            }
        )
    }
    // 注册上传文件
    upload(data: { file: File }) {
        // 使用requestClient的put方法，上传文件到/orders/importOrders接口，data为上传的文件，headers为请求头，'Content-Type'为multipart/form-data
        return requestClient.post(
            `/stockRegisterLog/import`,
            { file: data.file },
            {
                headers: {
                    'Content-Type': 'multipart/form-data'
                }
            }
        )
    }
    // 开始工作
    start(params: any) {
        return requestClient.post<null>('/stockRegisterLog/startWork', params)
    }
   
    // 工作详情进度
    readWorkProgress(id: number) {
        return requestClient.get(`/stockRegisterLog/readWorkProgress?workId=${id}`)
    }
    // 工作结束
    endWork(id: number) {
        return requestClient.get(`/stockRegisterLog/endWork?workId=${id}`)
    }
     // 导出
    export(type: number) {
        let url = apiURL + `/stockRegisterLog/export?type=${type}`
        window.open(url)
    }
    // 清空
    clear(batchNumber: string) {
        return requestClient.get(`/stockRegisterLog/clear?batchNumber=${batchNumber}`)
    }
    statuseEdit(params: Partial<sellerItemForm>) {
        return requestClient.put<null>(`/buser/edit/status/`, params)
    }
    // 账号包装/stockPackLog/index
    getPagePackagingList(params: ApiPaginationParams<{ username?: string }>) {
        return requestClient.get<ApiPagination<sellerPageListItem>>(
            '/stockPackLog/index',
            {
                params
            }
        )
    }
    // 账号包装上传文件
    uploadPackaging(data: { file: File }) {
        // 使用requestClient的put方法，上传文件到/orders/importOrders接口，data为上传的文件，headers为请求头，'Content-Type'为multipart/form-data
        return requestClient.post(
            `/stockPackLog/import`,
            { file: data.file },
            {
                headers: {
                    'Content-Type': 'multipart/form-data'
                }
            }
        )
    }
    // 账号包装开始工作
    startPack(params: any) {
        return requestClient.post<null>('/stockPackLog/startWork', params)
    }
    // 账号包装工作详情进度
    readPackWorkProgress(id: number) {
        return requestClient.get(`/stockPackLog/readWorkProgress?workId=${id}`)
    }
    // 账号包装工作结束
    endPackWork(id: number) {
        return requestClient.get(`/stockPackLog/endWork?workId=${id}`)
    }
    // 账号包装清空
    clearPack(batchNumber: string) {
        return requestClient.get(`/stockPackLog/clear?batchNumber=${batchNumber}`)
    }
}
